package com.loto.webapp.action.ajax;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;
import com.loto.webapp.common.BaseAction;
import com.loto.webapp.util.Files;

public class RightAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8445608854377991347L;
	private String msg;
	private String rights;
	private String userId;

	public String execute() throws Exception {
		if (rights != null && rights.length() > 0 && userId != null) {
			if (rights.endsWith("^"))
				rights = rights.substring(0, rights.length() - 1);
			String[] splitRights = rights.split("\\^");

			if (Files.buildConfigFile(ServletActionContext.getRequest(),
					splitRights, userId))
				msg = "suc";
			else
				msg = "err";

		} else
			msg = "err";
		return SUCCESS;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	@JSON(serialize = false)
	public String getRights() {
		return rights;
	}

	public void setRights(String rights) {
		this.rights = rights;
	}

	@JSON(serialize = false)
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

}
